﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DDDProject.Aspects;
using DDDProjectSample.Application.Controllers;

namespace DDDProjectSample.WebUI
{
    public partial class NewMessage : System.Web.UI.Page
    {
        [InjectComponent]
        private ForumsController _forumsController;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            // Creates the new message
            _forumsController.CreateMessage(
                TextBoxMessage.Text,
                Int64.Parse(this.Request.QueryString["TopicId"]),
                User.Identity.Name);

            // Redirects to the topic's page
            RedirectToTopicPage();
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            // Redirects to the topic's page
            RedirectToTopicPage();
        }

        private void RedirectToTopicPage()
        {
            Response.Redirect(String.Format(
                "~/Topic.aspx?Id={0}&ForumId={1}",
                Request.QueryString["TopicId"],
                Request.QueryString["ForumId"]));
        }
    }
}
